import React from 'react';
import {inject, observer} from 'mobx-react';
import {Spin} from 'antd'

const toJS = mobx.toJS;
import LoadLogs from '../../../public/loadlog/loadLogs';
import {WeaLocaleProvider}  from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
@inject ('planReportViewStore')
@observer
export default class PlanLog extends React.Component {
  constructor (props) {
    super (props);
    this.state = {};
    this.store = this.props.planReportViewStore;
  }

  getNameALink = (resourceid, resourcename) => {
    let href = 'javaScript:openhrm(' + resourceid + ');';
    return (
      <a href={href} onClick={e => window.pointerXY (e)} class="autoWrap">
        {resourcename}
      </a>
    );
  };

  morePlanLog = () => {
    const {planReportViewStore} = this.props;
    if (planReportViewStore.planLog.logType == 'noView') {
      planReportViewStore.planLog.logType = 'all';
      planReportViewStore.planLog.datas = [];
      planReportViewStore.planLog.lastcount = 0;
    }

    planReportViewStore.getPlanLog ();
  };
  scrollToAnchor = anchorName => {
    if (anchorName) {
      let anchorElement = document.getElementById (anchorName);
      if (anchorElement) {
        anchorElement.scrollIntoView ();
      }
    }
  };
  render () {
    const {planReportViewStore} = this.props;
    let {planLog} = planReportViewStore;
    planLog = toJS (planLog);
    const {datas} = planLog;
    if (datas) {
      for (var i = 0; i < datas.length; i++) {
        datas[i].operatevalue = datas[i].operatetype;
      }
    }

    return (
      <div className="planlog" id="plan-log">
        <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@ee9ige`} spining={this.store.logLoading}>
        <LoadLogs ecId={`${this && this.props && this.props.ecId || ''}_LoadLogs@nga6ol`}
          morename={this.store.planLog.logType == 'noView' ? getLabel('20234','显示全部')  : getLabel('387979','加载更多') }
          moretitle={
            this.store.planLog.logType == 'noView' ? getLabel('509061','显示包括查看在内的所有日志记录') : getLabel('387979','加载更多') 
          }
          onMoreClick={this.morePlanLog}
          lastcount={planLog.lastcount}
          logsData={datas}
        />
        </Spin>
      </div>
    );
  }
}
